﻿@{
    ViewBag.Title = "Home Page";
}
<style>
    .send {
        float: right;
        padding-top: 20px;
    }

    .shou {
        float: left;
    }

    .shoucanel {
        width: 100%;
        height: 1px;
        float: left
    }

    .sendchanel {
        width: 100%;
        height: 1px;
        float: left;
        margin-top: 30px;
    }
</style>
<div style="border: 1px solid red; width: 100%;">
    <div style="border: 1px solid black; width: 90%; height: 300px; margin: 0px auto" id="container">
        @*<div class="shoucanel">
                <div class="shou">收</div>
                <div class="send">发</div>
            </div>
            <div class="sendchanel">
                <div class="shou">收</div>
                <div class="send">发</div>
            </div>*@
    </div>

    <div style=" width: 90%; height: 300px; margin: 0px auto">
        <textarea style="border: 1px solid black; width: 100%; height: 300px; margin: 0px auto" id="message"></textarea>
    </div>
    <input type="button" value="发送" onclick="sendmes()" style="margin: 0px auto; width: 90%;margin-left: 5%">
    <br />
    <br />
    <input type="button" value="接收" onclick="GetMessage()" style="margin: 0px auto; width: 90%;margin-left: 5%">
</div>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
    $(function() {
     
    });
    function sendmes() {
        var val = $("#message").val();
        $("#container").append(" <div class=\"sendchanel\"><div class=\"send\">" + val + "</div></div>");
        $("#message").val("");
        var type = '@ViewBag.type';
        $.ajax({
            url: "/Home/SendMessage?message=" + val + "&type=" + type+"",
            type: "get",
            dataType: "json",
            async: false,
            success: function (data) {

                    alert(data);

            },
            error: function (e) {

            }
        });
    }

    function GetMessage() {
        var type = '@ViewBag.type';
        var chanerl = "";
        switch (type) {
        case "admin":
            chanerl = "gust";
            break;
        case "gust":
            chanerl = "admin";
            break;
        }
        $.ajax({
            url: "/Home/GetMessList?type=" + chanerl + "",
            type: "get",
            dataType: "json",
            async: false,
            success: function (data) {
                $(data).each(function (i, e) {
                    alert(e);
                });
            },
            error: function (e) {

            }
        });
    }
</script>